package ai.people.netmon.telegram.service.impl;

import ai.people.netmon.framework.domain.telegram.entity.Users;
import ai.people.netmon.framework.model.response.PageResponse;
import ai.people.netmon.telegram.domain.request.channels.UsersRequest;
import ai.people.netmon.telegram.mapper.UserMapper;
import ai.people.netmon.telegram.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 用户服务实现
 *
 * @author yuanqinglong
 * @date 2022/1/7 18:35
 */
@Service
public class UserServiceImpl implements UserService {


    @Autowired
    private UserMapper userMapper;

    /**
     * 分页查询用户
     *
     * @param usersConditions 用户环境
     * @return {@link PageResponse}<{@link Users}>
     */
    @Override
    public PageResponse selectUserPage(UsersRequest usersConditions) {
        Page<Users> usersPage = new Page<>(usersConditions.getPageNo(), usersConditions.getPageSize());
        LambdaQueryWrapper<Users> conditions = usersConditions.createConditions();
        conditions.select(Users::getId, Users::getFirstName, Users::getUsername).eq(Users::getDeleted, false);
        Page<Users> selectPage = userMapper.selectPage(usersPage, conditions);
        return new PageResponse(selectPage.getRecords(),selectPage.getTotal());
    }
}
